<template>
    <div class="sidebar">
        <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="sidebar.collapse" background-color="#2f4050"
            text-color="#bfcbd9" active-text-color="#fff" unique-opened router>
            <!--  有内容的卡片 -->
            <div v-if="!sidebar.collapse" class="logo-element">
                <el-row>
                    <el-col>
                        <el-card class="box-card" :body-style="{ padding: '0px'}">
                            <el-avatar style="width:80px; height: 80px" :src="avatarUrl"  />
                            <div style="padding: 8px;color: #BFCBD9; font-size: 14px;">
                                <span>{{ user.userName }}</span>
                            </div>
                            <div style="padding: 8px;font-size: 14px;">
                                <el-dropdown  :hide-on-click="false" @command="handleCommand" size="large" >
                                    <span class="el-dropdown-link">
                                        {{ user.userRole }}
                                    </span>
                                    <template #dropdown>
                                        <el-dropdown-menu class="user-name">
                                            <el-dropdown-item command="modifyPwd">修改密码</el-dropdown-item>
                                            <el-dropdown-item command="profile">个人资料</el-dropdown-item>
                                            <el-dropdown-item divided command="loginout">安全退出</el-dropdown-item>
                                        </el-dropdown-menu>
                                    </template>
                                </el-dropdown>
                            </div>

                        </el-card>
                    </el-col>
                </el-row>
            </div>
            <div v-else class="logo-element">
                <el-row>
                    <el-col>
                        <el-card class="box-card01" :body-style="{ padding: '0px' }">
                            <div style="padding: 14px;color: #fff;">
                                <span>:)</span>
                            </div>
                        </el-card>
                    </el-col>
                </el-row>


            </div>
            <template v-for="item in menuList">
                <template v-if="item.subMenus">
                    <el-sub-menu :index="item.menuUrl + item.id" :key="item.id">
                        <template #title>
                            <!-- <el-icon>
                                <component :is="item.iconName"></component>
                            </el-icon> -->
                            <i :class="'iconfont ' + item.iconName"></i>
                            <span>{{ item.menuName }}</span>
                        </template>
                        <template v-for="subItem in item.subMenus">
                            <el-sub-menu v-if="subItem.subMenus" :index="subItem.menuUrl" :key="subItem.id">
                                <template #title>{{ subItem.menuName }}</template>
                                <el-menu-item v-for="(threeItem, i) in subItem.subMenus" :key="i"
                                    :index="threeItem.menuUrl">
                                    {{ threeItem.menuName }}
                                </el-menu-item>
                            </el-sub-menu>
                            <el-menu-item v-else :index="subItem.menuUrl">
                                <!-- <el-icon>
                                   <component :is="subItem.iconName"></component>
                                 </el-icon> -->
                                <!-- <i class="iconfont icon-big-circle"></i> -->
                                <i :class="'iconfont ' + subItem.iconName"></i>
                                {{ subItem.menuName }}
                            </el-menu-item>
                        </template>
                    </el-sub-menu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.menuUrl" :key="item.id">
                        <!-- <el-icon>
                            <component :is="item.iconName"></component>
                        </el-icon> -->
                        <!-- <el-icon>
                            <Edit />
                        </el-icon> -->
                        <i :class="'iconfont ' + item.iconName"></i>
                        <template #title>{{ item.menuName }}</template>
                    </el-menu-item>
                </template>
            </template>

        </el-menu>
    </div>
</template>

<script setup >
import { computed, reactive } from 'vue';
import { useSidebarStore } from '../stores/sidebar';
import { useRoute, useRouter } from 'vue-router';
import avatarUrl from '../assets/imgs/img.jpg'
//tudo 数据需要从登录会保存状态中读取。。。
const user = reactive({
    // userName: localStorage.getItem("ms_username"),
    userName: 'CVX',
    userRole: 'CVX'
})

const menuList = [
    {
        "id": 1,
        "menuName": "首页",
        "menuUrl": "dashboard",
        "iconName": "icon-home",
	    "subMenus":null
	},
    {
        "id": 2,
        "menuName": "会员管理",
        "menuUrl": "#",
        "iconName": "icon-users",
        "subMenus":[
            {
                "id": 3,
                "menuName": "会员",
                "menuUrl": "member",
                "iconName": "icon-circle",
                "subMenus": null
            },
            {
                "id": 4,
                "menuName": "会员卡",
                "menuUrl": "memberCard",
                "iconName": "icon-circle",
                "subMenus": null
            },
            {
                "id": 5,
                "menuName": "会员绑定",
                "menuUrl": "memberBind",
                "iconName": "icon-circle",
                "subMenus": null
            }
        ]
    },
    {
        "id": 6,
        "menuName": "团课管理",
        "menuUrl": "#",
        "iconName": "icon-object-group",
        "subMenus":[
             {
                "id": 7,
                "menuName": "团课课程",
                "menuUrl": "courseList",
                "iconName": "icon-circle",
                "subMenus": null
            },
            {
                "id": 8,
                "menuName": "团课课表",
                "menuUrl": "courseSchedule",
                "iconName": "icon-circle",
                "subMenus": null
            },
            {
                "id": 9,
                "menuName": "团课预约设置",
                "menuUrl": "courseReservation",
                "iconName": "icon-circle",
                "subMenus": null
            }
        ]
    
    },
    {
        "id": 10,
        "menuName": "老师管理",
        "menuUrl": "teacherList",
        "iconName": "icon-yonghu",
        "subMenus": null
    },
     {
        "id": 11,
        "menuName": "数据统计",
        "menuUrl": "#",
        "iconName": "icon-chart",
        "subMenus": [
            {
                "id": 12,
                "menuName": "会员卡统计",
                "menuUrl": "cardListStat",
                "iconName": "icon-circle",
                "subMenus": null
            },
            {
                "id": 13,
                "menuName": "收费统计",
                "menuUrl": "cardCostStat",
                "iconName": "icon-circle",
                "subMenus": null
            },
            {
                "id": 14,
                "menuName": "消课统计",
                "menuUrl": "classCostStat",
                "iconName": "icon-circle",
                "subMenus": null
            },
            {
                "id": 15,
                "menuName": "总课次统计",
                "menuUrl": "classHourStat",
                "iconName": "icon-circle",
                "subMenus": null
            },
            
            {
                "id": 16,
                "menuName": "新增与流失统计",
                "menuUrl": "memberNumStat",
                "iconName": "icon-circle",
                "subMenus": null
            },
        ]

    },
    {
        "id": 17,
        "menuName": "微信设置",
        "menuUrl": "weChat",
        "iconName": "icon-yonghu",
        "subMenus": null
    },
    {
        "id": 18,
        "menuName": "应用中心(新)",
        "menuUrl": "appStore",
        "iconName": "icon-yonghu",
        "subMenus": null
    },

]

const route = useRoute();
const onRoutes = computed(() => {
    return route.path;
});
const router = useRouter()
const sidebar = useSidebarStore();

const handleCommand = (command) => {
    if (command == 'loginout') {//退出登录
        console.log('--------loginout----')
        //todo  需要开发者自行修改。。
        // localStorage.removeItem('ms_username');
        // localStorage.removeItem('token')
        localStorage.clear()
        router.push('/login')
    } else if (command == 'profile') {//个人资料
        router.push('/profile')
    } else if(command==='modifyPwd'){//修改密码
         router.push('/modifyPwd')
    }
};
</script>

<style scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 0px;
    bottom: 0;
    overflow-y: scroll;
    /* background-color: #2f4050; */
    background-color: #2f4050;
}

.sidebar::-webkit-scrollbar {
    width: 0;

}

.sidebar-el-menu:not(.el-menu--collapse) {
    width: 251px;
}

.sidebar>ul {
    height: 100%;
}

/* .avatar {
    background-color:#324157;
    color: #fff;
    padding-left: 20px;
    align-items: center;
    
} */

 .el-dropdown-link {
  cursor: pointer;
  /* color: var(--el-color-primary); */
  color: #BFCBD9;
  display: flex;
  align-items: center;
}

.el-dropdown-menu__item {
    text-align: center;
}

.box-card {
    background: url('../assets/img/header-profile.png');
    border: 0;
    color: #BFCBD9;
    /* padding-left: 20px; */
    padding: 33px 14px;
    width: 250px;
    height: 105px;
}
.box-card01 {
    text-align: center;
    background: url('../assets/img/header-profile.png');
    border: 0;
    height: 50px;
    color: #fff;
    font-size: 18px;
}

.logo-element {
   margin-bottom: 15px;
} 


/* .el-menu-item.is-active {
     color: white; 
} */
.iconfont {
    margin-right: 8px;
    font-size: 13px;
}

.user-name{
    width: 135px;
    align-items: center;

}

</style>
